package com.hystrix;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;

public class ZuulFallbackDemo implements ZuulFallbackProvider {

	public ClientHttpResponse fallbackResponse() {
		return new ClientHttpResponse(){
			 
			public InputStream getBody() throws IOException {
				String retVal = "return by Hystrix";				
				return new ByteArrayInputStream(retVal.getBytes());
			}
 
			public HttpHeaders getHeaders() {
				HttpHeaders headers = new HttpHeaders();
		        return headers;
			}
 
			public HttpStatus getStatusCode() throws IOException {
				
				return HttpStatus.OK;
			}
 
			public int getRawStatusCode() throws IOException {
				
				return HttpStatus.OK.value();
			}
 
			public String getStatusText() throws IOException {
				
				return HttpStatus.OK.getReasonPhrase();
			}
 
			public void close() {				
				
			}
			
		};

	}

	public String getRoute() {
		return "sayHello";
	}

}
